1934B - Yet Another Coin Problem - CodeForces Solution


brute force dp greedy

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>

#ifdef jlocal
#include<jdebug/debug.hpp>
#else
#define debug(...) 0;
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define all(x) x.begin(),x.end()

const ld pi = 3.14159265358979323846L;
const ld sqrt2 = 1.41421356237309504880L;
const ll p = 73;
const ll mod = 1e9 + 123;

vi dp = {0, 1, 2, 1, 2, 3, 1, 2, 3, 2, 1, 2, 2, 2, 3, 1, 2, 3, 2, 3, 2, 2, 3, 3, 3, 2, 3, 3, 3, 4, 2};


int main(){
#ifndef jlocal
    ios::sync_with_stdio(0); cin.tie(0);
#endif
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        if (n <= 30){
            cout << dp[n] << endl;
            continue;
        }

        int base = n/15 - 1;
        int mod = dp[(n-base*15)%30];
        int res = base + mod;
        cout << res << endl;
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

337B - Routine Problem
1392D - Omkar and Bed Wars
76E - Points
762C - Two strings
802M - April Fools' Problem (easy)
577B - Modulo Sum
1555B - Two Tables
1686A - Everything Everywhere All But One
1469B - Red and Blue
1257B - Magic Stick
18C - Stripe
1203B - Equal Rectangles
1536A - Omkar and Bad Story
1509A - Average Height
1506C - Double-ended Strings
340A - The Wall
377A - Maze
500A - New Year Transportation
908D - New Year and Arbitrary Arrangement
199A - Hexadecimal's theorem
519C - A and B and Team Training
631A - Interview
961B - Lecture Sleep
522A - Reposts
1166D - Cute Sequences
1176A - Divide it
1527A - And Then There Were K
1618E - Singers' Tour
1560B - Who's Opposite
182B - Vasya's Calendar